package br.ufrj.ppgi.infovis.toolbar;

import org.mt4j.components.bounds.IBoundingShape;
import org.mt4j.components.visibleComponents.widgets.MTTextArea;
import org.mt4j.util.MTColor;
import org.mt4j.util.font.FontManager;
import org.mt4j.util.font.IFont;
import org.mt4j.util.math.Vector3D;


import processing.core.PApplet;
import processing.core.PImage;

public class MTToolbarButtonWithLabel extends MTToolbarButton {
	private String label;
	private MTTextArea mttxt;
	private MTTextArea mttxt_sd;

	public MTToolbarButtonWithLabel(PImage texture, PApplet applet, String label, MTColor fontcolor) {
		super(texture, applet);
		this.label = label;
		
		IFont font = FontManager.getInstance().createFont(applet, "arial.ttf", 35, MTColor.WHITE);
		IFont font_sd = FontManager.getInstance().createFont(applet, "arial.ttf", 35, MTColor.BLACK);
		
		mttxt = new MTTextArea(applet, font);
		//mttxt.setFillColor(MTColor.BLACK);
		//mttxt.set
		mttxt.setNoStroke(true);
		mttxt.setNoFill(true);
		mttxt.setText(label);
		mttxt.setPickable(false);
		
		mttxt_sd = new MTTextArea(applet, font_sd);
		
		//mttxt.set
		mttxt_sd.setNoStroke(true);
		mttxt_sd.setNoFill(true);
		mttxt_sd.setText(label);
		mttxt_sd.setPickable(false);
		//mttxt_sd.setFillColor(MTColor.BLACK);
		

		Vector3D center = this.getCenterPointLocal();
		Vector3D pos = new Vector3D(center);
		
		pos.setY(center.y + 70);
		
		Vector3D pos_sd = new Vector3D(pos);
		pos_sd.setY(pos.y + 2);
		pos_sd.setX(pos.x + 2);

		mttxt.setPositionGlobal(pos);
		mttxt_sd.setPositionGlobal(pos_sd);
		
		
		/*
		Vector3D center = this.getCenterPointLocal();
		Vector3D pos = new Vector3D(center);
		
		pos.setY(center.y - 50);
		
		IBoundingShape bs = mttxt.getBounds();
		Vector3D vs[] = bs.getVectorsGlobal();
		float maxx = vs[0].x;
		float minx = vs[0].x;
		for (Vector3D v : vs) {
			if (maxx < v.x) maxx = v.x;
			if (minx > v.x) minx = v.x;
			System.out.println(v);
		}
		
		float width = maxx - minx;
		*/
		
		this.addChild(mttxt);
		this.addChild(mttxt_sd);
		mttxt_sd.sendToFront();
		mttxt.sendToFront();
	}

	public String getLabel() {
		return label;
	}

}
